<?php

/** 
 * 用户友盟信息模型
 */
class User_um_info_mdl extends MY_Model {
	
	/**
	 */
	public function __construct() {
		parent::__construct ();
		$this->_table = parent::T_USER_UM_INFO;
	}
	/**
	 * 保存用户的友盟device_token
	 * @param int $userID
	 * @param string $deviceToken
	 * @param string $system ios/android
	 * @return boolean
	 */
	public function saveDeviceToken($userID,$deviceToken,$system){
		$where = array (
				'userID' => $userID,
				'system' => $system 
		);
		$row = $this->db->where ( $where )->from ( $this->_table )->limit ( 1 )->get ()->row_array ();
		if (! empty ( $row )) {
			if ($row ['deviceToken'] == $deviceToken) {
				return TRUE;
			}
			
			return $this->db->set ( 'deviceToken', $deviceToken )->where ( $where )->update ( $this->_table );
		}
		
		$insert = $where;
		$insert ['deviceToken'] = $deviceToken;
		return $this->db->insert ( $this->_table, $insert );
	}
	
	
	
}

